package database

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/go-sql-driver/mysql"
)

type MySql struct {
	instance *sql.DB
}

func Open(name string, user string, password string, host string, port string) *MySql {
	connection := fmt.Sprintf("%s:%s@tcp(%s:%s)/"+name, user, password, host, port)
	instance, err := sql.Open("mysql", connection)
	if err != nil {
		log.Fatal(err.Error())
	}
	return &MySql{instance}
}

// 1
func (db *MySql) Execute(sql string) *MySql {
	_, err := db.instance.Exec(sql)
	if err != nil {
		log.Fatal(err.Error())
	}
	return db
}
